package com.charging.business.utils;

import com.charging.common.utils.StringUtils;

/**
 * @author JerryLu
 * @date 2024/9/27 16:05
 * @description 一些公用的计算工具类
 */
public class BasicUtil {

    private static final StringBuilder specialInfo = new StringBuilder();

    public static void resetSpecialInfo() {
        specialInfo.setLength(0);
    }

    public static void setSpecialInfo(String info) {
        if (info.length() > 0 && specialInfo.length() > 0) {
            specialInfo.append("|");
        }
        specialInfo.append(info);
    }

    public static String getSpecialInfo() {
        String specialType = specialInfo.toString();
        // 去除首尾部的'|'
        if (specialType.startsWith("|")) {
            specialType = specialType.substring(1);
        }
        if (specialType.endsWith("|")) {
            specialType = specialType.substring(0, specialType.length() - 1);
        }
        return specialType;
    }

    /**
     * 车牌格式化，转大写，去除车牌中的"."(军车、武警车会有的情况)
     *
     * @param vehicleId
     * @return
     */
    public static String formatVehicleId(String vehicleId) {
        return vehicleId.toUpperCase().replace(".", "").trim();
    }

    /**
     * 车牌比较
     *
     * @param plate1 - 车牌1
     * @param plate2 - 车牌2
     * @param cmpClr - 是否比较颜色 true - 比较颜色  false - 不比较颜色
     * @return boolean
     */
    public static boolean compareVehicleId(String plate1, String plate2, boolean cmpClr) {
        if (!cmpClr) {
            String cmp1 = StringUtils.split(plate1, 2, "_")[0];
            String cmp2 = StringUtils.split(plate2, 2, "_")[0];

            return cmp1.compareToIgnoreCase(cmp2) == 0;
        } else {
            return plate1.compareToIgnoreCase(plate2) == 0;
        }
    }
}
